package com.jarvis.pzz.modules.shop.adapter;

import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jarvis.pzz.R;
import com.jarvis.pzz.models.ShopListMapFindModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jarvis.liu on 9/12/2016.
 */
public class BannerAdapter extends BaseQuickAdapter<ShopListMapFindModel> {

    private BannerAdapter customerAdapter;

    public BannerAdapter(int layoutResId, List<ShopListMapFindModel> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, ShopListMapFindModel shopListModel) {

        LinearLayout lin_sign = baseViewHolder.getView(R.id.lin_sign);
        LinearLayout lin_bg = baseViewHolder.getView(R.id.lin_bg);
        TextView tv_demo = baseViewHolder.getView(R.id.tv_demo);
        ImageView img = baseViewHolder.getView(R.id.img);
        ImageView img_adv = baseViewHolder.getView(R.id.img_adv);
        ImageView img_top = baseViewHolder.getView(R.id.img_top);
        TextView tv_name = baseViewHolder.getView(R.id.tv_name);
        TextView tv_shop_rent = baseViewHolder.getView(R.id.tv_shop_rent);
        TextView tv_shopIntroduce = baseViewHolder.getView(R.id.tv_shopIntroduce);
        lin_bg.setVisibility(View.VISIBLE);
        img_adv.setVisibility(View.GONE);
        Glide.with(mContext).load(shopListModel.getShopThumbnailImgPath()).placeholder(R.drawable.img_default).error(R.drawable.img_default).into(img);
        tv_name.setText(shopListModel.getShopTitle());
        tv_shop_rent.setText(shopListModel.getShopRent());
        String sign = shopListModel.getShopLables();
        tv_shopIntroduce.setText(shopListModel.getShopIntroduce());
        if (TextUtils.isEmpty(shopListModel.getShopAuditingState())) {
            img_top.setVisibility(View.GONE);
        } else {
            if ("1".equals(shopListModel.getShopAuditingState())) {
                img_top.setVisibility(View.VISIBLE);
            } else {
                img_top.setVisibility(View.GONE);
            }
        }
        if (!TextUtils.isEmpty(sign)) {
            String[] split = sign.split(",");
            List<String> list_sign = new ArrayList<>();
            for (int i = 0; i < split.length; i++) {
                list_sign.add(split[i]);
            }
            lin_sign.removeAllViews();
            int count = list_sign.size();
            if (count > 3) {
                count = 3;
            }
            for (int i = 0; i < count; i++) {
                TextView tv2 = new TextView(mContext);
                tv2.setText(list_sign.get(i));
                tv2.setBackgroundColor(mContext.getResources().getColor(R.color.grey_6));
                tv2.setTextColor(mContext.getResources().getColor(R.color.grey_7));
                tv2.setTextSize(TypedValue.COMPLEX_UNIT_SP, 8);
                tv2.setGravity(Gravity.CENTER);
                tv2.setMaxLines(1);
                tv2.setEllipsize(TextUtils.TruncateAt.END);
                tv2.setPadding(3, 3, 3, 3);
                ViewGroup.LayoutParams layoutParams1 = tv_demo.getLayoutParams();
                tv2.setLayoutParams(layoutParams1);

                LinearLayout lin = new LinearLayout(mContext);
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                if (i != 0) {
                    params.setMargins(10, 0, 0, 0);
                }
                lin.setLayoutParams(params);
                lin.addView(tv2);
                lin_sign.addView(lin);
            }
        }
    }

}
